package com.zemo.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.zemo.dao.ProductDao;
import com.zemo.entity.Product;

@Repository
@SuppressWarnings("unchecked")
public class ProductDaoImpl implements ProductDao {

	@Autowired
	private HibernateTemplate hibernateTemplate;
	//习惯使用sessionFactory也可以使用sessionFactory
//	@Resource
//	private SessionFactory sessionFactory;
	
	@Override
	public List<Product> listAllProducts() {
		String queryString = "FROM Product";
		return hibernateTemplate.find(queryString);
	}

	@Override
	public Product getProduct(int id) {
		return hibernateTemplate.get(Product.class, id);
	}

}
